package com.example.tests;

import static org.testng.Assert.assertEquals;

import java.util.Collections;
import java.util.List;

import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;

public class ContactCreationTests extends TestBase{

  @Test(dataProvider = "randomValidContactGenerator")
  public void testAddContact(ContactData contact) throws Exception {
	app.getNavigationHelper().openMainPage();
   
    //save old state
    List<ContactData> oldList = app.getContactHelper().getContacts();
    
    //actions    
	app.getContactHelper().initNewContactCreation();  
 	app.getContactHelper().fillContactForm(contact);
    app.getGroupHelper().submitGroupCreation();
    app.getNavigationHelper().returntoHomePage();
  
  
  //save new state
  List<ContactData> newList = app.getContactHelper().getContacts();
  
  //compare states
  oldList.add(contact);
  Collections.sort(oldList);
  Collections.sort(newList);
  assertEquals(newList, oldList);
  }
}
  